app.controller('HeaderCtrl', function GoodsTypeCtrl($scope, $http, $uibModal, $location, $log, filterUtil, filterFilter) {

  $scope.openModal = function () {
    var modalInstance = $uibModal.open({
      templateUrl: 'modifyPass.html',
      controller: modifyPass,
      size: 'lg'
    });
    modalInstance.result.then(function (result) {
      var obj = result.obj;
      $http({
        method: 'post',
        url: '/modifyPass',
        data:obj
      }).then(function successCallback(response) {
        console.log(response)
        if (response.data && response.status && response.status !== 200) {
          toastr.error('服务器异常');
          return;
        } else if (response.data.code == 200){
          toastr.success('修改成功');
          $("#logout").trigger("click");
          $scope.obj = undefined;
        } else if (response.data.code == -1013) {
          toastr.error('新密码输入有误');
        } else if (response.data.code == -1001) {
          toastr.error('原密码输入有误');
        }
      }, function errorCallback(response) {

      });
    }, function () {
      $log.info('Modal dismissed at: ' + new Date());
    });
  };
});

function modifyPass($scope, $uibModalInstance) {
  $scope.obj = {};

  $scope.ok = function (action) {
    $uibModalInstance.close({obj: $scope.obj});
  };

  $scope.cancel = function () {
    $uibModalInstance.dismiss('cancel');
  };

}
